# *_*coding:utf-8 *_*
# @Author : Reggie
# @Time : 2021/2/18 下午 1:33 
import time
from pathlib import Path

from dataclasses import dataclass

from logger import logger
from base_m3u8 import DownLoad_M3U8


@dataclass
class Download(DownLoad_M3U8):
    def download_all_ts(self):
        self.download_all_ts2()


def main():
    # m3u8_url = 'https://newv1.xinliangfc.com/01yxkcGuyG.m3u8'
    # 使用系统变量修改代理, 可以让m3u8解析也经过代理
    # os.environ["http_proxy"] = "http://127.0.0.1:10809"
    # os.environ["https_proxy"] = "https://127.0.0.1:10809"
    # print(os.environ)
    m3u8_url = 'https://hls-hw.xvideos-cdn.com/videos/hls/03/38/5b/03385b0b742284442a02c882b1a520e3/hls-360p-85774.m3u8?e=1613636805&l=0&h=45ccdc54422b518a362c6bbfa6a16e6f'
    m3u8_url = 'https://cdn77-vid.xvideos-cdn.com/iF4mrHR0S16xIdUJxOhezQ==,1615884740/videos/hls/16/89/b2/1689b2573e4eba193d80f42935db1c24-1/hls-480p.m3u8'

    file_name = "Hiddendana on chaturbate"
    ts_path = "../tmp"
    out_path = Path(r"C:\download").joinpath(Path(__file__).stem)
    proxies = {
        'sock5': '127.0.0.1:10808',
        'http': '127.0.0.1:10809',
        'https': '127.0.0.1:10809'
    }
    # proxies = {}
    headers = {
        'User-Agent': 'Mozilla/5.0 (Windows NT 6.3; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.92 Safari/537.36'
    }
    download_proxies = proxies
    download_headers = {
        # "Referer": "https://www.xvideos.com/video60461749/drunkchinese",
        # "Origin": "https://www.xvideos.com",
        # "Host": "hls-hw.xvideos-cdn.com",
        'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36 dingtalk-win/1.0.0 nw(0.14.7) DingTalk(4.6.39-Release.10) Mojo/1.0.0 Native AppType(release)',
    }

    start = time.time()
    base_uri = m3u8_url.rsplit("/", 1)[0]
    print(base_uri)
    M3U8 = Download(
        m3u8_url=m3u8_url,
        file_name=file_name,
        out_path=out_path,
        ts_path=ts_path,
        proxies=proxies,
        base_uri=base_uri,
        rm_ts=False,
        headers=headers,
        max_workers=1,
        download_headers=download_headers,
        download_proxies=download_proxies
    )
    M3U8.run()
    end = time.time()
    print('耗时:', end - start)


if __name__ == '__main__':
    main()
